/**
  ******************************************************************************
  * @file    main.c
  * @author  Iron
  * @date    2018-08-03
  * @version v1.0
  * @brief   Control board Application
  */

/** @addtogroup GROUP_MAIN
  * @{
  */

/* includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "tasks_common.h"
#include "bsp.h"
#include "bsp_led.h"
#include "bsp_watchdog.h"

/* private typedef -----------------------------------------------------------*/
/* private macro -------------------------------------------------------------*/
/* private variables ---------------------------------------------------------*/
void MX_LWIP_Init(void);

/**
  * @note: Task stack in CCM SRAM，部分数据将导致 DMA 冲突，eg. USART DMA / SPI DMA
  *        解决方法采用 xTaskCreateStatic 使用普通 SRAM ,
  */
//#define HEAP_USE_CCM

#ifndef HEAP_USE_CCM
    static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#endif

static const HeapRegion_t xHeapRegions[] =
{
#ifndef HEAP_USE_CCM
    {
        .pucStartAddress = ucHeap,
        .xSizeInBytes = configTOTAL_HEAP_SIZE,
    },
#else
    {
        .pucStartAddress = (uint8_t *)0x10000000,
        .xSizeInBytes = 0x10000,
    },
#endif
    { NULL, 0 }               // << Terminates the array.
};

/* private function prototypes -----------------------------------------------*/
/* private functions ---------------------------------------------------------*/

void MainTask(void *pvArgument)
{
    /* Configure the hardware ready to run the Application. */
    bsp_init();

    /* init code for LWIP */
    MX_LWIP_Init();

    /* applicaiton tasks start */
    task_cli_start();

    /* loop forever */
    for (;;)
    {
        vTaskDelay(pdMS_TO_TICKS(100));
        /* watchdog */
        bsp_watchdog_keepalive();
        /* system led blink */
        // led_toggle( LED_SYSTEM );
    }
}

/**
  * @brief  main
  * @param  None.
  * @retval OK: normally return;
  *         ERROR: error;
  */
int main(void)
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
    /* Configure the system clock */
    SystemClock_Config();
    /* Define multiple heap regions for use by heap_5.c */
    vPortDefineHeapRegions(xHeapRegions);
    /* Create the thread(s) */
    xTaskCreate(MainTask, "system", 256, NULL, SYS_TASK_PRI_SYSTEM, NULL);
    /* Start the scheduler. */
    vTaskStartScheduler();
    /* If all is well, the scheduler will now be running, and the following line
    will never be reached.  If the following line does execute, then there was
    insufficient FreeRTOS heap memory available for the idle and/or timer tasks
    to be created.  See the memory management section on the FreeRTOS web site
    for more details. */
    for (;;);
}


/**
  * @}
  */

/******************* (C)COPYRIGHT 2018 ***** END OF FILE *********************/
